package com.viboo.concern.service.impl;

import com.viboo.concern.dao.ChatTokenMapper;
import com.viboo.concern.entity.ChatToken;
import com.viboo.concern.service.TokenService;
import com.viboo.concern.util.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author avanline
 * @descriotion
 * @date 2018-03-20 10:26
 */
@Service("tokenService")
@Slf4j
public class TokenServiceImpl implements TokenService {

    @Autowired
    public ChatTokenMapper chatTokenMapper;

    @Override
    public void insert(ChatToken record) {
        try {
            record.setExpiresIn(System.currentTimeMillis() / 1000 + Constants.EXPIRES_IN);
            chatTokenMapper.insert(record);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public ChatToken selectByPrimaryKey(String appId) {
        try {
            return chatTokenMapper.selectByPrimaryKey(appId);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }

    @Override
    public void updateByPrimaryKey(ChatToken record) {
        try {
            record.setExpiresIn(System.currentTimeMillis() / 1000 + Constants.EXPIRES_IN);
            chatTokenMapper.updateByPrimaryKey(record);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
